package com.crl.module.media.core
{
	import flash.events.Event;
	import flash.events.NetStatusEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	
	public class LNetConnection extends NetConnection
	{
		public function LNetConnection()
		{
			this.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			this.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
		}
		
		/**
		 * 
		 * @param	event
		 * @return
		 */
		private function netStatusHandler(event:NetStatusEvent):void {
			switch (event.info.code) {
				case StreamState.SUCCESS :
					this.connectStream();
					break;
				case StreamState.NOFOUND :
					trace("Stream not found: ");
					break;
				case StreamState.STOP :
					//主要为跟mp3发布的事件一样;
					this.dispatchEvent(new Event(Event.SOUND_COMPLETE));
					break;
				case StreamState.START :
					//trace("Stream start");
					break;
				case StreamState.FULL :
					//trace("Stream buffer is full");
					break;
				case StreamState.EMPTY :
					//trace("Stream buffer is empay");
					break;
			}
		}
		
		public var stream:NetStream;
		private function connectStream():void{
			this.stream= new NetStream(this);
			this.stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			this.stream.bufferTime=5;
			this.stream.client =this;
		}
		
		
		/**
		 * 
		 * @param	event
		 * @return
		 */
		private function securityErrorHandler(event:SecurityErrorEvent):void {
			trace("securityErrorHandler: " + event);
		}
		
		
		
		public var duration:int=0;
		public var width:Number=0;
		public var height:Number=0;
		public var framerate:int=0;
		
		public function onMetaData(info:Object):void {
			this.duration=info.duration;
			this.width=info.width;
			this.height=info.height;
			this.framerate=info.framerate;
			
			//trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
		}
		public function onCuePoint(info:Object):void {
			//trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
		}
		
	}
}